const mongoose = require('mongoose')

const taskSchema = new mongoose.Schema({
    parentId: { //父级id
        type: mongoose.SchemaTypes.ObjectId,
        ref: 'Task',
    },
    taskname: { //任务名称
        type: String,
        required: true
    },
    creator: { //发起人/审核人
        type: mongoose.SchemaTypes.ObjectId,
        ref: 'User'
    },
    worker: [{ //执行人
        type: mongoose.SchemaTypes.ObjectId,
        ref: 'User'
    }],
    status: { //任务的状态 0进行中 1审核中 2被打回 3已完成
        type: Number,
        enum: [0, 1, 2, 3],
        default: 0
    },
    process: { //进度
        type: Number,
    },
    describe: { //任务描述
        type: String,
    },
    endtime: { //实际结束时间
        type: Date,
    },
    fileAddress: [{
        // userId: { type: mongoose.SchemaTypes.ObjectId,ref:'User' },
        name:String,
        describe: String,
        files: Array,
        createdAt:{
            type: Date,
            default:Date.now()
        },
        process: Number,
        void:{
            type:Boolean,
            default:true
        }
    }],
    grade: { //任务等级
        type: Number,
        default: 0
    }
}, {
    // 创建时间和更新时间
    timestamps: true
})

module.exports = mongoose.model('Task', taskSchema, 'task')